package com.ymatou.iapi.trading.sellerquery2.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.ordersync.service.SyncVerifyService;
import com.ymatou.query.seller.trading.api.parameter.ExistsSellerOrdersBean;
import com.ymatou.query.seller.trading.api.parameter.Seller.ExistsSellerOrdersResponse;
import com.ymatou.query.seller.trading.api.service.OrderCreate;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.common.enums.LogisticsTypeEnum;
import com.ymttest.common.enums.OrderStatusEnum;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

/**
 * @date 2016-07-18
 * @author songyefeng
 * @desc 卖家订单是否存在
 */
@SuppressWarnings("rawtypes")
@TestSuite
public class Ts_ExistsSellerOrders {

	private static ExistsSellerOrdersBean request;
	//	private static com.ymatou.query.seller.trading.api.service.ExistsSellerOrdersCall call;
	private static com.ymatou.iapi.trading.sellerquery2.service.ExistsSellerOrdersCall call;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("卖家订单是否存在");
	}

	@Before
	public void caseUp() {
		request = new ExistsSellerOrdersBean();
		//		call = new com.ymatou.query.seller.trading.api.service.ExistsSellerOrdersCall();
		call = new com.ymatou.iapi.trading.sellerquery2.service.ExistsSellerOrdersCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verify() {
		ExistsSellerOrdersResponse expectedResponse = new ExistsSellerOrdersResponse();
		ConstructExpectedResponse(expectedResponse);
		ExistsSellerOrdersResponse actualResponse = call
				.getExistsSellerOrdersResponse();
		DataUtil.verifyEquals(expectedResponse.isToBeAccepted(),
				actualResponse.isToBeAccepted(), "验证ToBeAccepted");
		// DataUtil.verifyEquals(expectedResponse.isToBeAppliedPostpay(),
		// actualResponse.isToBeAppliedPostpay(), "验证ToBeAppliedPostpay");
		// DataUtil.verifyEquals(false,
		// actualResponse.isToBeAppliedPostpay(), "验证ToBeAppliedPostpay");
		DataUtil.verifyEquals(expectedResponse.isToBeConfirmed(),
				actualResponse.isToBeConfirmed(), "验证ToBeConfirmed");
		DataUtil.verifyEquals(expectedResponse.isToBeDelivered(),
				actualResponse.isToBeDelivered(), "验证ToBeDelivered");
		DataUtil.verifyEquals(expectedResponse.isToBePaid(),
				actualResponse.isToBePaid(), "验证ToBePaid");
		/*	DataUtil.verifyEquals(expectedResponse.isToBePostpaid(),
					actualResponse.isToBePostpaid(), "验证ToBePostpaid");*/
		//add by sean 
		if (expectedResponse.getOrderCountDic().size() > 0) {
			Logger.comment("开始校验 orderCountDic ");

			for (Integer key : expectedResponse.getOrderCountDic().keySet()) {
				DataUtil.verifyEquals(
						expectedResponse.getOrderCountDic().get(key),
						actualResponse.getOrderCountDic().get(key), "校验状态为:"
								+ key + "的数量");
			}

		}

	}
	private void ConstructExpectedResponse(ExistsSellerOrdersResponse response) {
		Process(response);
	}

	private void Process(ExistsSellerOrdersResponse response) {
		StringBuffer sql = new StringBuffer();

		if (request.getOrderCreatedTimeBegin() == null
				&& request.getOrderCreatedTimeEnd() == null
				&& request.getOrderPaidTimeBegin() == null
				&& request.getOrderPaidTimeEnd() == null) {
			request.setOrderCreatedTimeBegin(YMTDateUtil.addMonths(-5,
					YMTDateUtil.YMDHMS));
		}

		String indexName = null;
		String cond = GetConditionAndSetArgs(indexName);

		GetStatusSQL("ToBePaid", indexName, sql,
				OrderStatusEnum.OrderEstablish.getValue(), null);
		sql.append(cond + "\n");
		sql.append("union all " + "\n");

		GetStatusSQL("ToBeAccepted", indexName, sql,
				OrderStatusEnum.AccountPaid.getValue(), null);
		sql.append(cond + "\n");
		sql.append("union all " + "\n");

		GetStatusSQL("ToBeAppliedPostpay", indexName, sql,
				OrderStatusEnum.SellerAccept.getValue(), false);
		sql.append(cond + "\n");
		sql.append("union all " + "\n");

		GetStatusSQL("ToBePostpaid", indexName, sql,
				OrderStatusEnum.ApplyForPostPay.getValue(), null);
		sql.append(cond + "\n");
		sql.append("union all " + "\n");

		GetStatusSQL("ToBeDelivered", indexName, sql,
				OrderStatusEnum.SellerAccept.getValue(), true);
		sql.append(cond + "\n");
		sql.append("union all " + "\n");

		GetStatusSQL("ToBeConfirmed", indexName, sql,
				OrderStatusEnum.Shipped.getValue(), null);
		sql.append(cond + "\n");

		List<Map> l = new DefaultWapper().executeSql(sql);
		if (!DataUtil.isNullOrEmpty(l)) {
			HashMap<Integer, Integer> dic = new HashMap<Integer, Integer>();
			for (Map m : l) {

				if (m.containsValue("ToBePaid") && (Integer) m.get("count") > 0) {
					response.setToBePaid(true);
					dic.put(1, (Integer) m.get("count"));
				}

				if (m.containsValue("ToBeDelivered")
						&& (Integer) m.get("count") > 0) {
					response.setToBeDelivered(true);
					dic.put(17, (Integer) m.get("count"));
				}

				if (m.containsValue("ToBeAccepted")
						&& (Integer) m.get("count") > 0) {
					response.setToBeAccepted(true);
					dic.put(2, (Integer) m.get("count"));
				}

				if (m.containsValue("ToBeConfirmed")
						&& (Integer) m.get("count") > 0) {
					response.setToBeConfirmed(true);
					dic.put(3, (Integer) m.get("count"));
				}

			}

			response.setOrderCountDic(dic);

		}
	}
	private static void GetStatusSQL(String name, String index,
			StringBuffer sql, int status, Boolean paidInFull) {
		sql.append("select top 1 '")
				.append(name)
				//add by sean
				.append("' as orderState,COUNT (DISTINCT o.iOrderId) as count from ymt_orders o with(nolock");
		if (!DataUtil.Stringg.IsNullOrWhiteSpace(index)) {
			sql.append("index = " + index);
		}
		//add by sean 过滤砍价团非成团的订单
		sql.append(") LEFT JOIN dbo.Ymt_OrderBiz b ON b.OrderId = o.iOrderId ");

		if (!DataUtil.Stringg.IsNullOrWhiteSpace(request.getProductName())
				|| status == OrderStatusEnum.Shipped.getValue()
				|| !DataUtil.Stringg.IsNullOrWhiteSpace(request.getProductId())
				|| !DataUtil.Stringg.IsNullOrWhiteSpace(request
						.getReceiverName())
				|| !DataUtil.Stringg.IsNullOrWhiteSpace(request
						.getReceiverPhone())
				&& request.getDomesticDelivered() != null
				&& !DataUtil.Booleann.GetValueOrDefault(request
						.getDomesticDelivered())) {
			sql.append(" join ymt_orderinfo(nolock) i on i.iorderid = o.iorderid ");
		}
		// add by sean 03-30 增加物流单号
		if (!DataUtil.Stringg.IsNullOrWhiteSpace(request.getDeliveryCode())) {
			sql.append(" inner join Ymt_BillCodeSummaryToOrders as [billCode] on o.iOrderId=[billCode].orderid ");
			sql.append(" inner join Ymt_BillCodeSummary as [billSummary] on  [billCode].BillCodeSummaryID=[billSummary].billCodeSummaryID");
		}

		sql.append(" where ");
		//add by sean 过滤砍价团非成团的订单
		sql.append(
				" ( b.OrderId IS NULL  OR b.BizStatus =3) and o.itradingstatus = ")
				.append(status).append(" ");

		if (status == OrderStatusEnum.Shipped.getValue()
				&& request.getDomesticDelivered() != null) {
			if (DataUtil.Booleann.GetValueOrDefault(request
					.getDomesticDelivered())) {
				sql.append(" and o.bdomesticdelivered = 1 ");
			} else {
				sql.append(" and i.iCatalogStatus = ")
						.append(LogisticsTypeEnum.PackageDelivery.getValue())
						.append(" and o.bdomesticdelivered is null ");
			}
		}
		if (null != request.getReceiverName()) {
			sql.append(" and o.sReceivePerson = '" + request.getReceiverName()
					+ "'");
		}
		if (null != request.getReceiverPhone()) {
			sql.append(" and o.sPhone = '" + request.getReceiverPhone() + "'");
		}
		if (null != request.getProductId()) {
			sql.append(" and i.sProductId = '" + request.getProductId() + "'");
		}

		if (status == OrderStatusEnum.Shipped.getValue()
				&& null != request.getDeliveryCode()) {
			sql.append(" and [billSummary].billCode =  '"
					+ request.getDeliveryCode() + "'");
		}
	}
	private static String GetConditionAndSetArgs(String indexName) {

		StringBuffer sql = new StringBuffer();

		sql.append(" and o.ibuyerid = " + request.getSellerId());

		boolean orderOrGroupIdOnly = false;
		if (request.getOrderId() != null) {
			sql.append(" and o.iorderid = " + request.getOrderId());
			orderOrGroupIdOnly = true;
			indexName = "PK_Ymt_Orders";
		}

		if (request.getOrderGroupId() != null) {
			sql.append(" and o.imainorderid = " + request.getOrderGroupId());
			orderOrGroupIdOnly = true;
			indexName = "IDX_Ymt_Orders_iMainOrderId";
		}
		// bool tCreated = false, tPaid = false;
		if (request.getOrderCreatedTimeBegin() != null) {
			sql.append(" and o.dAddTime >= '"
					+ request.getOrderCreatedTimeBegin() + "'");
		}
		if (request.getOrderCreatedTimeEnd() != null) {
			sql.append(" and o.dAddTime <= '"
					+ request.getOrderCreatedTimeEnd() + "'");
		}

		if (request.getOrderPaidTimeBegin() != null) {
			sql.append(" and ( (o.[dPostPaidTime] is null and o.[dPaidTime] >= '"
					+ request.getOrderPaidTimeBegin()
					+ "') or o.[dPostPaidTime] >= '"
					+ request.getOrderPaidTimeBegin() + "')");
		}
		if (request.getOrderPaidTimeEnd() != null) {
			sql.append(" and ( (o.[dPostPaidTime] is null and o.dPaidTime <= '"
					+ request.getOrderPaidTimeEnd()
					+ "')  or o.[dPostPaidTime] <= '"
					+ request.getOrderPaidTimeEnd() + "')");
		}

		if (!DataUtil.Stringg.IsNullOrWhiteSpace(request.getBuyerNickName())) {
			sql.append(" and o.sBuyerLoginId = '" + request.getBuyerNickName()
					+ "' ");
		}

		if (!DataUtil.Stringg.IsNullOrWhiteSpace(request.getProductName())) {
			sql.append(" and i.sTitle like '%" + request.getProductName()
					+ "%' ");
		}

		if (DataUtil.Booleann.GetValueOrDefault(request.getOrderRefund())) {
			sql.append(" and o.iSalesRefundStatus is not null ");
		}

		if (!orderOrGroupIdOnly) {
			indexName = "idx_Ymt_Orders_iBuyerId_iTradingStatus_bDomesticDelivered";
		}

		return sql.toString();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_001() {
		Logger.start(true, "卖家订单是否存在,只传SellerId");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			// request.setProductName("测试");
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_002() {
		Logger.start(true,
				"卖家订单是否存在,只传SellerId, orderCreatedTimeBegin,orderCreatedTimeEnd");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_003() {
		Logger.start(true,
				"卖家订单是否存在,只传SellerId, orderPaidTimeBegin,orderPaidTimeEnd");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderPaidTimeBegin(begin);
			request.setOrderPaidTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_004() {
		Logger.start(true, "卖家订单是否存在,productName筛选(es)");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			request.setProductName("商品");
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_005() {
		Logger.start(true,
				"卖家订单是否存在,只传SellerId, orderPaidTimeBegin,orderPaidTimeEnd");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderPaidTimeBegin(begin);
			request.setOrderPaidTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_ExistsSellerOrders_006() {
		Logger.start(
				true,
				"卖家订单是否存在,只传SellerId, orderPaidTimeBegin,orderPaidTimeEnd,domesticDelivered=false");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderPaidTimeBegin(begin);
			request.setOrderPaidTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_007() {
		Logger.start(true,
				"卖家订单是否存在,只传SellerId, orderCreatedTimeBegin,orderCreatedTimeEnd,orderID");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			request.setOrderId(105414161);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_008() {
		Logger.start(true,
				"卖家订单是否存在,只传SellerId, orderCreatedTimeBegin,orderCreatedTimeEnd,orderGroupId");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			request.setOrderGroupId(13913536);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_009() {
		Logger.start(
				true,
				"卖家订单是否存在,只传SellerId, orderCreatedTimeBegin,orderCreatedTimeEnd,orderRefund=true");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			request.setOrderRefund(true);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_010() {
		Logger.start(
				true,
				"卖家订单是否存在,只传SellerId, orderCreatedTimeBegin,orderCreatedTimeEnd,orderRefund=false");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			request.setOrderRefund(false);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_011() {
		Logger.start(true, "卖家订单是否存在, 根据buyerNickName筛选(es)");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(sellerId);
			String buyerNickName = String.valueOf(EnvSetup
					.getData("BuyUserName"));
			request.setBuyerNickName(buyerNickName);
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);

			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_012() {
		Logger.start(true, "卖家订单是否存在,验证productId筛选(es)");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			String cBegin = YMTDateUtil.getBeforeOrNextMonth(-1,
					YMTDateUtil.YMDTHMS_STRING);
			Logger.comment("准备测试数据");
			String productId = new OrderCreate().create1_M2cOrder(userId,
					sellerId).getsProductId();
			Thread.sleep(5000l);
			Logger.comment("完成准备测试数据");
			request.setSellerId(sellerId);
			request.setOrderRefund(false);
			String cEnd = YMTDateUtil.getBeforeOrNextMonth(0,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(cBegin);
			request.setOrderCreatedTimeEnd(cEnd);
			request.setProductId(productId);

			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_013() {
		Logger.start(true, "卖家订单是否存在,验证receiverName筛选");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			String cBegin = YMTDateUtil.getBeforeOrNextMonth(-1,
					YMTDateUtil.YMDTHMS_STRING);
			Logger.comment("准备测试数据");
			String receiverName = new OrderCreate().create1_M2cOrder(userId,
					sellerId).getsReceivePerson();
			Thread.sleep(2000l);
			Logger.comment("完成准备测试数据");
			request.setSellerId(sellerId);
			request.setOrderRefund(false);
			String cEnd = YMTDateUtil.getBeforeOrNextMonth(0,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(cBegin);
			request.setOrderCreatedTimeEnd(cEnd);
			request.setReceiverName(receiverName);

			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_014() {
		Logger.start(true, "卖家订单是否存在,验证receiverPhone筛选(es)");
		try {
			// 买手信息
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			String cBegin = YMTDateUtil.getBeforeOrNextMonth(-6,
					YMTDateUtil.YMDTHMS_STRING);
			Logger.comment("准备测试数据");
			String receiverPhone = new OrderCreate().create1_M2cOrder(userId,
					sellerId).getsPhone();
			Thread.sleep(2000l);
			Logger.comment("完成准备测试数据");
			request.setSellerId(sellerId);
			request.setOrderRefund(false);
			String cEnd = YMTDateUtil.getBeforeOrNextMonth(0,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(cBegin);
			request.setOrderCreatedTimeEnd(cEnd);
			request.setReceiverPhone(receiverPhone);

			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_015() {
		Logger.start(true, "卖家订单是否存在,传orderId,砍价团订单,组团成功,查询成功");
		try {
			// 买手信息
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			// 开团订单
			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 砍价团参团订单
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);
			// 参团
			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, 3);

			SyncVerifyService.getSyncResult(orderId);

			request.setSellerId(sellerId);

			request.setOrderId(orderId);
			call.setData(request);
			call.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_016() {
		Logger.start(true, "卖家订单是否存在,传orderId,砍价团订单,组团失败,查询成功");
		try {
			// 买手信息
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			// 开团订单
			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 砍价团参团订单
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);
			// 参团
			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, -3);

			SyncVerifyService.getSyncResult(orderId);

			request.setSellerId(sellerId);

			request.setOrderId(orderId);
			call.setData(request);
			call.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_017() {
		Logger.start(true, "卖家订单是否存在,传orderId,砍价团订单,组团中,查询成功");
		try {
			// 买手信息
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			// 开团订单
			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 砍价团参团订单
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);
			// 参团
			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, 0);

			SyncVerifyService.getSyncResult(orderId);

			request.setSellerId(sellerId);

			request.setOrderId(orderId);
			call.setData(request);
			call.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_018() {
		Logger.start(true,
				"卖家订单是否存在,传orderId,productName筛选(es)，砍价团订单,组团成功,查询成功");
		try {
			// 买手信息
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			// 开团订单
			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 砍价团参团订单
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);
			// 参团
			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, 3);

			SyncVerifyService.getSyncResult(orderId);

			request.setSellerId(sellerId);

			request.setOrderId(orderId);
			request.setProductName("砍价团");
			call.setData(request);
			call.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_019() {
		Logger.start(true,
				"卖家订单是否存在,传orderId,productName筛选(es)，砍价团订单,组团失败,查询成功");
		try {
			// 买手信息
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			// 砍价团id
			String bizId = placeOrderResp.getBizId();
			// 开团订单
			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 砍价团参团订单
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);
			// 参团
			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, -3);

			SyncVerifyService.getSyncResult(orderId);

			request.setSellerId(sellerId);

			request.setOrderId(orderId);
			request.setProductName("砍价团");
			call.setData(request);
			call.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_020() {
		Logger.start(true, "卖家订单是否存在,deliveryCode筛选");
		try {
			// 买手信息
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			Logger.comment("前置数据准备结束");

			OrderCallService orderCallService = new OrderCallService();
			// 应付款全金额 
			BigDecimal totalPrice = orderCallService
					.getNeedPrePayAmountOfCashBymainOrderId(tradingId);
			// 支付订单
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);

			// 保存物流信息
			String deliveryCode = SyncVerifyService.dispatched(orderId,
					sellerId);

			// 同步国内发货信息
			YmatouEasyCall YmatouEasyCall = new YmatouEasyCall("", "POST",
					"JSON");

			String orderJson = "{\"logisticsNos\":[\"" + deliveryCode + "\"]}";

			YmatouEasyCall
					.setUrl("http://operate.trading.iapi.ymatou.com/api/Notify/SyncOrderLogisticStatus");
			YmatouEasyCall.setData(orderJson);
			YmatouEasyCall.callService();

			SyncVerifyService.getSyncResult(orderId);

			request.setSellerId(sellerId);
			//request.setProductName("商品");
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);

			request.setDeliveryCode(deliveryCode);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_021() {
		Logger.start(true, "卖家订单是否存在,product_name,deliveryCode筛选(ES)");
		try {
			// 买手信息
			PlaceOrderResp placeOrderResp = PlaceOrderService
					.placeOrderWithOutCoupon();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			Logger.comment("前置数据准备结束");

			OrderCallService orderCallService = new OrderCallService();
			// 应付款全金额 
			BigDecimal totalPrice = orderCallService
					.getNeedPrePayAmountOfCashBymainOrderId(tradingId);
			// 支付订单
			orderCallService.orderPayRequest(userId, totalPrice, tradingId);

			// 接单
			orderCallService.acceptOrder(orderId, sellerId);

			// 保存物流信息
			String deliveryCode = SyncVerifyService.dispatched(orderId,
					sellerId);

			// 同步国内发货信息
			YmatouEasyCall YmatouEasyCall = new YmatouEasyCall("", "POST",
					"JSON");

			String orderJson = "{\"logisticsNos\":[\"" + deliveryCode + "\"]}";

			YmatouEasyCall
					.setUrl("http://operate.trading.iapi.ymatou.com/api/Notify/SyncOrderLogisticStatus");
			YmatouEasyCall.setData(orderJson);
			YmatouEasyCall.callService();

			SyncVerifyService.getSyncResult(orderId);

			request.setSellerId(sellerId);
			request.setProductName("商品");
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);

			request.setDeliveryCode(deliveryCode);
			call.setData(request);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerOrders_022() {
		Logger.start(true, "卖家订单是否存在,只传SellerId");
		try {
			// 买手信息
			int sellerId = 20223383;
			request.setSellerId(sellerId);

			// request.setProductName("测试");
			String begin = YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING);
			String end = YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING);
			request.setOrderCreatedTimeBegin(begin);
			request.setOrderCreatedTimeEnd(end);
			call.setData(request);
			call.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}